package com.terrynoya.fight.evaluation
{
	import com.terrynoya.fight.emuns.Operator;
	import com.terrynoya.fight.emuns.SymbolType;
	import com.terrynoya.fight.evaluation.token.OperatorData;
	import com.terrynoya.fight.evaluation.token.SymbolData;
	import com.terrynoya.fight.evaluation.token.TextData;
	import com.terrynoya.fight.evaluation.token.UnknownData;

	public class Token
	{
		private var _text:String;
		
		private var _data:TokenData;
		
		public function Token(text:String,data:TokenData)
		{
			this._text = text;
			this._data = data;
		}
		
		public function get text():String
		{
			return _text;
		}

		public function set text(value:String):void
		{
			_text = value;
		}

		public function get data():TokenData
		{
			return _data;
		}

		public function get length():int 
		{
			return this._text == null ? 0 : this._text.length;
		}
		
		public function toString():String
		{
			return this._text;
		}
		
		public function get asOperator():int 
		{
			var val:OperatorData = this.data as OperatorData
			if(val == null)
			{
				return Operator.None;
			}
			return val.operator;
		}
		
		public function get asText():String 
		{
			var val:TextData = this.data as TextData;
			if(val == null)
			{
				return null;
			}
			return this._text.substr(1,this._text.length - 2);
		}
		
		public function get asSymbol():String 
		{
			var data:SymbolData = this.data as SymbolData;
			if(data == null)
			{
				return SymbolType.None;
			}
			return data.symbol;
		}
		
		public function get asUnknown():String 
		{
			var data:UnknownData = this.data as UnknownData;
			if(data == null)
			{
				return null;
			}
			return this.text;
		}
	}
}